//
//  ZZCEmoticon.swift
//  weibo
//
//  Created by zhangzuchao on 2017/4/7.
//  Copyright © 2017年 zhangZuChao. All rights reserved.
//

import UIKit

class ZZCEmoticon: NSObject, NSCoding {
    //  表情描述
    var chs: String?
    //  图片名
    var png: String?
    //  表情类型 0: 图片表情, 1: emoji表情
    var type: String?
    //  emoji对应的16进制的字符串
    var code: String?
    //  图片 需要全路径 这个需要拼接
    var path: String?
    
    //  图片对应的文件夹
    var folderName: String?
    
    //防止init冲突 和下面那个
    override init() {
        super.init()
    }
    
    //   归档和解档  存储最近使用的表情
    func encode(with aCoder: NSCoder) {
        aCoder.encode(chs, forKey: "chs")
        aCoder.encode(png, forKey: "png")
        aCoder.encode(type, forKey: "type")
        aCoder.encode(code, forKey: "code")
        aCoder.encode(path, forKey: "path")
        aCoder.encode(folderName, forKey: "folderName")

    }
    
    required init?(coder aDecoder: NSCoder) {
        chs = aDecoder.decodeObject(forKey: "chs") as? String
        png = aDecoder.decodeObject(forKey: "png") as? String
        type = aDecoder.decodeObject(forKey: "type") as? String
        code = aDecoder.decodeObject(forKey: "code") as? String
        path = aDecoder.decodeObject(forKey: "path") as? String
        folderName = aDecoder.decodeObject(forKey: "folderName") as? String
        if type == "0" {
            //  图片表情, 需要获取最新的bundle路径加载图片
            path = ZZCEmoticonTools.sharedTools.emoticonBundle.path(forResource: folderName, ofType: nil)! + "/" + png!
        }
        
    }
}
